package org.itboys.mobile.service.mongo.site;

import org.apache.commons.collections.map.HashedMap;
import org.itboys.mobile.entity.mongo.JoinMessage;
import org.itboys.mobile.entity.mongo.JoinReplyMessage;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseMongoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 作者：zzq
 * 时间：2017/9/29
 * 描述：雄安加盟网_
 */
@Service
public class JoinSiteReplyMessageService extends BaseMongoService<JoinReplyMessage>{
    @Resource(name = "mobileDs")
    private MongoDataSource mobileDataSource;
    @Override
    protected MongoDataSource getMongoDataSource() {
        return mobileDataSource;
    }

    @Override
    protected Class<JoinReplyMessage> getEntityClass() {
        return JoinReplyMessage.class;
    }
    @Autowired
    private JoinSiteMessageService messageService;

    /**
     * 回复
     * @param productId
     * @param messageId
     * @param content
     */
    public void saveMessage(Long productId,Long messageId,String content){
        JoinMessage message=messageService.getById(messageId);
        super.save(new JoinReplyMessage(productId,messageId,message.getMemberRecordId(),content));

        message.setStatus(2);
        messageService.updateExceptEmpty(messageId,message);
    }


    /**
     * 企业获取回复留言
     * @param productId
     * @return
     */
    public List<JoinReplyMessage> selectProductMessage(Long productId){
        Map<String,Object> param=new HashMap<String,Object>();
        param.put("isDeleted",0);
        param.put("productId",productId);
        return super.list(param);
    }

    /**
     * 用户获取回复留言
     * @param memberRecordId
     * @return
     */
    public List<JoinReplyMessage> selectMemberMessage(Long memberRecordId){
        Map<String,Object> param=new HashMap<String,Object>();
        param.put("memberRecordId",memberRecordId);
        return super.list(param);
    }
}
